<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>三石影视 - 首页</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/hls.js@1.4.14/dist/hls.min.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#FF7D00',
                        dark: '#1E293B',
                        light: '#F8FAFC'
                    },
                    fontFamily: {
                        inter: ['Inter', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .text-shadow {
                text-shadow: 0 2px 4px rgba(0,0,0,0.1);
            }
        }

        /* 轮播图样式 */
        .swiper {
            width: 100%;
            height: 520px;
        }
        
        .swiper-slide {
            text-align: center;
            background: #000;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }
        
        .swiper-slide img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            object-position: center;
        }
        
        .swiper-button-next,
        .swiper-button-prev {
            color: #fff !important;
            background: rgba(0, 0, 0, 0.3);
            width: 40px !important;
            height: 40px !important;
            border-radius: 50%;
        }
        
        .swiper-button-next:after,
        .swiper-button-prev:after {
            font-size: 20px !important;
        }
        
        .swiper-pagination-bullet {
            background: #fff !important;
            opacity: 0.5;
        }
        
        .swiper-pagination-bullet-active {
            opacity: 1;
            background: #165DFF !important;
        }
    </style>
</head>
<body class="bg-gray-50 font-inter text-dark">
    <!-- 导航栏 -->
    <header class="sticky top-0 z-50 bg-white/90 backdrop-blur-sm shadow-sm">
        <div class="container mx-auto px-4 py-3 flex items-center relative">
            <!-- logo -->
            <a href="/" class="flex-shrink-0 flex items-center space-x-1 z-10">
                <i class="fa fa-play-circle text-primary text-3xl"></i>
                <span class="text-xl font-bold text-primary">三石影视</span>
            </a>
            <!-- 菜单绝对居中 -->
            <nav class="absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2 flex items-center space-x-8 z-0">
                <a href="/" class="font-medium {% if active_nav == 'home' %}text-primary border-b-2 border-primary pb-1{% else %}text-gray-600 hover:text-primary transition-colors{% endif %}">首页</a>
                <a href="{{ url_for('category_movie') }}" class="font-medium {% if active_nav == 'movie' %}text-primary border-b-2 border-primary pb-1{% else %}text-gray-600 hover:text-primary transition-colors{% endif %}">电影</a>
                <a href="{{ url_for('category_tv') }}" class="font-medium {% if active_nav == 'tv' %}text-primary border-b-2 border-primary pb-1{% else %}text-gray-600 hover:text-primary transition-colors{% endif %}">电视剧</a>
                <a href="{{ url_for('category_anime') }}" class="font-medium {% if active_nav == 'anime' %}text-primary border-b-2 border-primary pb-1{% else %}text-gray-600 hover:text-primary transition-colors{% endif %}">动漫</a>
                <a href="{{ url_for('category_variety') }}" class="font-medium {% if active_nav == 'variety' %}text-primary border-b-2 border-primary pb-1{% else %}text-gray-600 hover:text-primary transition-colors{% endif %}">综艺</a>
            </nav>
            <!-- 右侧搜索和头像 -->
            <div class="flex-shrink-0 flex items-center space-x-4 z-10 ml-auto">
                <div class="relative hidden md:block">
                    <form method="get" action="/">
                        <input type="text" name="q" value="{{ search_query|default('') }}" placeholder="搜索视频..." class="pl-10 pr-4 py-2 rounded-full bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary/50 w-64">
                        <button type="submit" class="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400"><i class="fa fa-search"></i></button>
                        <i class="fa fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                    </form>
                </div>
                <button class="md:hidden text-gray-600">
                    <i class="fa fa-search text-xl"></i>
                </button>
                {% if session.get('user_id') %}
                <div class="relative">
                    <button id="userMenuBtn" class="text-gray-600 hover:text-primary transition-colors">
                        <i class="fa fa-user-circle text-xl"></i>
                    </button>
                    <div id="userMenu" class="absolute right-0 mt-2 w-48 bg-white rounded-lg shadow-lg py-2 hidden">
                        <a href="{{ url_for('profile') }}" class="block px-4 py-2 text-gray-700 hover:bg-gray-100">
                            <i class="fa fa-user mr-2"></i>个人中心
                        </a>
                        {% if session.get('role') == 'admin' %}
                        <a href="{{ url_for('admin_dashboard') }}" class="block px-4 py-2 text-gray-700 hover:bg-gray-100">
                            <i class="fa fa-cog mr-2"></i>管理控制台
                        </a>
                        {% endif %}
                        <a href="{{ url_for('logout') }}" class="block px-4 py-2 text-gray-700 hover:bg-gray-100">
                            <i class="fa fa-sign-out-alt mr-2"></i>退出登录
                        </a>
                    </div>
                </div>
                {% else %}
                <a href="{{ url_for('login') }}" class="text-gray-600 hover:text-primary transition-colors">
                    <i class="fa fa-user-circle text-xl"></i>
                </a>
                {% endif %}
                <button class="md:hidden text-gray-600">
                    <i class="fa fa-bars text-xl"></i>
                </button>
            </div>
        </div>
    </header>

    <main class="container mx-auto px-4 py-8">
        <!-- 轮播图 -->
        <div class="relative mb-8 rounded-xl overflow-hidden shadow-lg">
            <div class="swiper">
                <div class="swiper-wrapper">
                    {% for video in videos[:5] %}
                    <div class="swiper-slide relative">
                        <img src="{{ video.cover }}" alt="{{ video.title }}" class="w-full h-full object-cover">
                        <div class="absolute inset-0 bg-gradient-to-t from-black/80 via-black/40 to-transparent">
                            <div class="absolute bottom-0 left-1/2 transform -translate-x-1/2 p-6 text-center w-full">
                                <h2 class="text-2xl font-bold text-white mb-2">{{ video.title }}</h2>
                                <p class="text-white/80 line-clamp-2">{{ video.description }}</p>
                                <a href="{{ url_for('play', video_id=video.id) }}" class="inline-block mt-4 px-6 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors">
                                    立即观看
                                </a>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
                <div class="swiper-pagination"></div>
                <div class="swiper-button-next"></div>
                <div class="swiper-button-prev"></div>
            </div>
        </div>

        <!-- 视频列表 -->
        <div class="grid grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
            {% for video in videos %}
            <div class="bg-white rounded-xl overflow-hidden shadow-md card-hover">
                <div class="relative">
                    <img src="{{ video.cover }}" alt="{{ video.title }}" class="w-full h-48 object-cover">
                    <div class="absolute top-2 right-2 bg-black/70 text-white text-xs px-2 py-1 rounded">
                        {{ video.rating }}分
                    </div>
                    <div class="absolute bottom-2 right-2 bg-black/70 text-white text-xs px-2 py-1 rounded">
                        <i class="fa fa-eye mr-1"></i>{{ video.views }}万
                    </div>
                    <div class="absolute inset-0 bg-black/30 opacity-0 hover:opacity-100 transition-opacity flex items-center justify-center">
                        <a href="{{ url_for('play', video_id=video.id) }}" class="bg-primary/90 text-white rounded-full w-14 h-14 flex items-center justify-center transform hover:scale-110 transition-transform" target="_blank">
                            <i class="fa fa-play text-xl"></i>
                        </a>
                    </div>
                </div>
                <div class="p-4">
                    <h3 class="font-semibold text-lg mb-2 line-clamp-1">{{ video.title }}</h3>
                    <div class="flex items-center text-sm text-gray-500 mb-2">
                        <span class="mr-3"><i class="fa fa-user mr-1"></i>{{ video.director }}</span>
                        <span><i class="fa fa-calendar mr-1"></i>{{ video.year }}</span>
                    </div>
                    <div class="flex flex-wrap gap-2">
                        {% for tag in video.tags %}
                        <span class="text-xs bg-gray-100 text-gray-600 px-2 py-1 rounded-full">{{ tag }}</span>
                        {% endfor %}
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </main>

    <footer class="bg-dark text-white py-10 mt-16">
        <div class="container mx-auto px-4">
            <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
                <div>
                    <h3 class="text-xl font-bold mb-4">三石影视</h3>
                    <p class="text-gray-400">提供高质量视频播放服务，享受流畅观影体验</p>
                </div>
                <div>
                    <h4 class="font-semibold mb-4">快速链接</h4>
                    <ul class="space-y-2">
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors">首页</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors">电影</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors">电视剧</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors">动漫</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="font-semibold mb-4">帮助中心</h4>
                    <ul class="space-y-2">
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors">常见问题</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors">使用指南</a></li>
                        <li><a href="#" class="text-gray-400 hover:text-white transition-colors">联系我们</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="font-semibold mb-4">关注我们</h4>
                    <div class="flex space-x-4">
                        <a href="#" class="text-gray-400 hover:text-white transition-colors">
                            <i class="fa fa-weibo text-xl"></i>
                        </a>
                        <a href="#" class="text-gray-400 hover:text-white transition-colors">
                            <i class="fa fa-wechat text-xl"></i>
                        </a>
                        <a href="#" class="text-gray-400 hover:text-white transition-colors">
                            <i class="fa fa-qq text-xl"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="border-t border-gray-700 mt-8 pt-8 text-center text-gray-500 text-sm">
                <p>© 2025 三石影视. 保留所有权利</p>
            </div>
        </div>
    </footer>

    <!-- 引入Swiper -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.css" />
    <script src="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.js"></script>
    
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        // 初始化轮播图
        try {
            const swiper = new Swiper('.swiper', {
                loop: true,
                autoplay: {
                    delay: 5000,
                    disableOnInteraction: false,
                },
                pagination: {
                    el: '.swiper-pagination',
                    clickable: true,
                },
                navigation: {
                    nextEl: '.swiper-button-next',
                    prevEl: '.swiper-button-prev',
                },
                effect: 'fade',
                fadeEffect: {
                    crossFade: true
                },
                centeredSlides: true,
                slidesPerView: 1,
                spaceBetween: 0,
                on: {
                    init: function() {
                        console.log('轮播图初始化成功');
                    },
                    error: function(error) {
                        console.error('轮播图初始化失败:', error);
                    }
                }
            });
        } catch (error) {
            console.error('轮播图初始化失败:', error);
        }

        // 用户菜单显示控制
        const userMenuBtn = document.getElementById('userMenuBtn');
        const userMenu = document.getElementById('userMenu');

        if (userMenuBtn && userMenu) {
            userMenuBtn.addEventListener('click', function(e) {
                e.stopPropagation();
                userMenu.classList.toggle('hidden');
            });
            
            // 点击其他地方关闭菜单
            document.addEventListener('click', function(e) {
                if (!userMenu.contains(e.target) && !userMenuBtn.contains(e.target)) {
                    userMenu.classList.add('hidden');
                }
            });
        }

        // 图片加载错误处理
        document.querySelectorAll('img').forEach(img => {
            img.addEventListener('error', function() {
                this.src = '/static/images/placeholder.jpg';
                this.alt = '图片加载失败';
            });
        });

        // 视频卡片悬停效果
        document.querySelectorAll('.card-hover').forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.transform = 'translateY(-5px)';
                this.style.transition = 'transform 0.3s ease';
            });
            
            card.addEventListener('mouseleave', function() {
                this.style.transform = 'translateY(0)';
            });
        });

        // 搜索框优化
        const searchInput = document.querySelector('input[name="q"]');
        if (searchInput) {
            searchInput.addEventListener('input', function() {
                if (this.value.length > 0) {
                    this.classList.add('ring-2', 'ring-primary/50');
                } else {
                    this.classList.remove('ring-2', 'ring-primary/50');
                }
            });
        }
    });
    </script>
</body>
</html>    